package com.df.happylearn.utils;

import android.text.TextUtils;

import java.util.List;

/**
 * Created by dingfeng on 2015/12/25.
 */
public class StringUtil {

    // 判断字符串是否为空
    public static boolean isEmpty(String s) {
        if (!TextUtils.isEmpty(s) && s != null) {
            return false;
        }
        return true;
    }

    // String列表转换成用逗号隔开的字符串
    public static String formatStringList(List<String> list) {
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < list.size(); i++) {
            if (i == 0) {
                sb.append(list.get(i).trim());
            }else {
                sb.append("," + list.get(i).trim());
            }
        }
        return sb.toString();
    }

    public static String getSubStr(String str, int num) {
        String result = "";
        int i = 0;
        while (i < num) {
            int lastFirst = str.lastIndexOf('/');
            result = str.substring(lastFirst) + result;
            str = str.substring(0, lastFirst);
            i++;
        }
        return result.substring(1);
    }
}
